import { TypedUseSelectorHook, useSelector } from 'react-redux';
import { combineReducers } from 'redux';
import store from '..';
import channelReducer from './channel';
import userReducer from './user';
import searchReducer from './search';
import ArticleReducer from './article';
import commentsReducer from './comments';

// combineReducers合并reducer
const rootReducer = combineReducers({
  user: userReducer,
  // 合并reducer
  channel: channelReducer,

  scarch: searchReducer,
  article: ArticleReducer,

  comments: commentsReducer,
});

export default rootReducer;

// 解决在ts中使用useSelector,state类型丢失的问题
export type RootState = ReturnType<typeof store.getState>;

export type AppDispatch = typeof store.dispatch;

export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
